package com.imay.live.view.dialog;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.imay.base.fragment.BaseDialogFragment;
import com.imay.live.R;

/**
 * Created by chan on 2017/4/11.
 */

public class NoticeDialogFragment extends BaseDialogFragment {
    private TextView mNoticeTitle, mNoticeMsg;
    private Button mNoticeButtom;
    private static String MESSAGE = "message";
    private static String TITLE = "title";
    private static String BUTTONTEXT = "buttomText";

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_notice;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mNoticeTitle = $(R.id.notice_tv_title);
        mNoticeMsg = $(R.id.notice_tv_message);
        mNoticeButtom = $(R.id.notice_btn_positive);

        mNoticeButtom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        Bundle bundle = getArguments();
        String message = bundle.getString(MESSAGE);
        String title = bundle.getString(TITLE);
        String buttomText = bundle.getString(BUTTONTEXT);
        if (!TextUtils.isEmpty(message)) {
            setMsg(message);
        }

        if (!TextUtils.isEmpty(title)) {
            setTitle(title);
        }

        if (!TextUtils.isEmpty(buttomText)) {
            setButtom(buttomText);
        }
    }

    public static NoticeDialogFragment newInstance(String message, String title, String buttomText) {
        NoticeDialogFragment instance = new NoticeDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putString(MESSAGE, message);
        bundle.putString(TITLE, title);
        bundle.putString(BUTTONTEXT, buttomText);
        instance.setArguments(bundle);
        return instance;
    }


    /**
     * 设置title
     *
     * @param title
     */
    public void setTitle(String title) {
        mNoticeTitle.setText(title);
        mNoticeTitle.setVisibility(View.VISIBLE);
    }

    /**
     * 设置信息
     *
     * @param msg
     */
    public void setMsg(String msg) {
        mNoticeMsg.setText(msg);
    }

    /**
     * 设置按钮
     *
     * @param buttom
     */
    public void setButtom(String buttom) {
        mNoticeButtom.setText(buttom);
    }
}
